require('../css/sports.less')
require('../fonts/iconfont.css')

document.ready(function () {
    utils.addFooter();

    //选项卡切换
    let text = document.querySelectorAll('.text1')
    for (let i = 0; i < 3; i++) {
        text[i].addEventListener('click', function () {
            for (let j = 0; j < 3; j++) {
                text[j].classList.remove("tabs")
            }
            text[i].classList += ' tabs'
        })
    }

    //获取用户消息
    let user = JSON.parse(localStorage.getItem('user'))
    let Url = 'http://139.9.177.51:8099'
    //获取节点
    let newCourse = document.querySelector('.newCourse')
    let course = document.querySelector('.course')
    let courseBox = document.querySelector('.courseBox')

    //取得用户课程信息
    $http.get('/sports/courseList?id=' + user.userId, function (res) {
        let arr = res.data
        //判定最新课程
        let newData = arr.find(function (item) {
            return item.latest == 1
        })
        //清空最新课程页面
        let html = ''
        // 遍历--渲染最新课程页面
        html += `
             <div class="title f18">最新课程</div>
             <a  href="../page/sportsDetail.html?id=${newData.courseId}">
             <div class="Box">
                 <div class="box"><img src="${Url + newData.imgurl}" alt=""></div>
                 <div class="textbox">
                      <div class="texttitle f16">${newData.name}</div>
                     <div class="text f12 c9a">${newData.desc}</div>
                  </div>
             </div>
             </a>
             
        `
        newCourse.innerHTML = html

        //去除最新课程
        arr.splice(arr.indexOf(arr.find(function (item) {
            return item.latest == 1
        })), 1)

        //清空课程页面
        let html1 = ''
        // 遍历--渲染课程页面
        arr.forEach(function (item) {
            html1 += `
                <a href="../page/sportsDetail.html?id=${item.courseId}">
                    <div class="box pr"><img src="${Url + item.imgurl}" alt="">
                        <div class="locBox pa">
                            <div class="f20 text1">${item.name}</div>
                            <div class="f14 text2">${item.desc}</div>
                        </div>
                    </div>
                </a>
            `
            courseBox.innerHTML = html1
        });





    })





















})